package com.homework.mergesort;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class DriverMS {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        //1，获取配置信息和封装任务
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        //2，设置jar 加载路径
        job.setJarByClass(DriverMS.class);

        //3，设置map和reduce
        job.setMapperClass(MapperMS.class);
        job.setReducerClass(ReduceMS.class);

        //4,设置map输出类型
        job.setMapOutputKeyClass(MSBean.class);
        job.setMapOutputValueClass(NullWritable.class);

        //5,设置reduce最终输出类型
        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(Text.class);

        //6，设置输入输出路径
        FileInputFormat.setInputPaths(job, new Path("D:\\Hadoop\\module3-1\\in"));
        FileOutputFormat.setOutputPath(job, new Path("D:\\Hadoop\\module3-1\\out"));

        //提交job
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);

    }
}
